//
//  main.m
//  Block和typedef
//
//  Created by wenjim on 17/10/13.
//  Copyright © 2017年 WenJim. All rights reserved.
//

#import <Foundation/Foundation.h>

int sum(int value,int value2)
{
//    printf("%i + %i = %i\n",value,value2,value + value2);
    return  value + value2;
}

int minus(int value,int value2)
{
//    printf("%i - %i = %i\n",value,value2,value - value2);
    return value - value2;
}

typedef int (*calculate)(int,int);
// 注意：利用typedef 给block 起别名，和指向函数的指针一样，block 变量的名称就是别名
typedef int (^calculateBlock)(int,int);

int main(int argc, const char * argv[]) {
    
    /*
//    int (*sumP)(int,int);
//    sumP = sum;
    
    calculate sumP = sum;
    NSLog(@"sum = %i",sumP(10,20));
    
    
    
//    int (*minusP)(int,int);
//    minusP = minus;

    calculate minusP = minus;
    NSLog(@"minus = %i",minusP(15,10));
    */
    
    
//    int (^sumBlock)(int,int) = ^(int value,int value2)
//    {
//        return value + value2;
//    };
    calculateBlock sumBlock = ^(int value,int value2)
    {
        return value + value2;
    };
    NSLog(@"sum = %i",sumBlock(20,10));
    
    
//    int (^minusBlock)(int,int) = ^(int value,int value2){
//        
//        return value - value2;
//    };
    calculateBlock minusBlock = ^(int value,int value2)
    {
        return value - value2;
    };
    
    NSLog(@"minus = %i",minusBlock(20,10));
    
    
    
    
    
    return 0;
}
